home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / banging_the_metal / qdos / qdos4amiga2 / romsrc / sys / startup_asm < prev    next >
Text File  |  2000-01-03  |  6KB  |  220 lines

  1. */beginfile STARTUP_asm
  2. ; --------------------------------------------------------------
  3. ; STARTUP_asm - startup routines
  4. ;         - last modified 15/05/95
  5. ; QDOS-Amiga sources by Rainer Kowallik
  6. ;    ...some changes by Mark J Swift
  7. ; --------------------------------------------------------------
  8. ;*/beginoverlay
  9.  
  10. ; --------------------------------------------------------------
  11. ; Target for Jumps to reset the system
  12.  
  13. RST_SYS:
  14. SYS_STARt:
  15. QL_START:
  16. ; clear QL screen
  17.     lea    $20000,a0
  18.     move.w    #$1FFF,d0
  19. CLR_SCR:
  20.     clr.l    (a0)+
  21.     dbra    d0,CLR_SCR
  22. ;
  23.     dc.l    $2E780000    ; move.l $0,a7 Get SSP !A68k
  24.     move.l    a7,d0        ; Calculate start of
  25.     andi.w    #-$8000,d0    ; system variables
  26.     move.l    d0,a6
  27. ; set system system stack and lomem
  28.     lea    $480(a6),a7    ; Set SSP.
  29.     move.l    a7,a4        ; Set lomem.
  30.  
  31.     cmpi.w    #SV.IDENT,(a6)    ; Check if sys vars exist
  32.     bne.s    QDOS256K
  33. ; get himem from system variables
  34.     move.l    SV_RAMT(a6),a5    ; Get ramtop.
  35.     cmpa.l    a4,a5        ; use only if valid
  36.     bgt.s    CLR_VAR
  37. ; if lomem and himem not valid, can only assume a minimum system
  38. QDOS256K:
  39.     move.l    a0,a6        ; Put sys vars after scrn#1
  40.     lea    $480(a6),a7    ; Set SSP.
  41.     move.l    a7,a4        ; Set lomem.
  42.     lea    $60000,a5    ; Set ramtop
  43. ; clear system variables.
  44. CLR_VAR:
  45.     move.l    a6,a0        ; Start of memory to clear.
  46. CLR_VMEM:
  47.     clr.l    (a0)+
  48.     cmpa.l    a7,a0
  49.     bne.s    CLR_VMEM
  50. ; clear system memory, lomem to himem
  51. ;CLR_SYS:
  52. ;     move.l     a4,a0         ; Get start of ram.
  53. ;CLR_SMEM:
  54. ;     clr.l     (a0)+
  55. ;     cmpa.l     a5,a0         ; Clear until end of ram.
  56. ;     bne.s     CLR_SMEM
  57. ; initialise QL hardware registers
  58.     move.b    #$8,MC_STAT    ; 8 colour mode, screen #1
  59. ; initialise system variables.
  60. INISYVAR:
  61.     move.w    #SV.IDENT,(a6)    ; Store QDOS id.
  62.  
  63. RLOC0E    jsr    SET_ATTN-ORG0    ; check processor type
  64.  
  65.     move.l    a5,SV_RAMT(a6)    ; Store ramtop
  66.     move.l    a5,SV_RESPR(a6)    ; base of resident procs
  67.     move.l    a5,SV_TRNSP(a6)    ; base of transient progs
  68.     move.b    #-$40,SV_PCINT(a6) ; Current value for PC
  69.                  ; interrupt flag.
  70.  
  71. ; initialise pointers to slave blocks.
  72.     move.l    a5,d0        ; Top of ram.
  73.     bsr.s    SLVTBL_LEN    ; Max len of slave blk table
  74.     move.l    a7,a2        ; First byte after sys vars
  75.     lea    SV_BTPNT(a6),a3    ; Address of ptr to most
  76.                 ; recent slave block.
  77.     moveq    #0,d6
  78.     bsr.s    INI_TABLE    ; Initialise pointers to
  79.                 ; slave blocks.
  80. ; find combined length of job and channel tables.
  81.     move.l    a5,a0        ; Get himem.
  82.     suba.l    a4,a0        ; subtract lomem
  83.     move.l    a0,d0        ; Tables are at most 1/128th
  84.     lsr.l    #7,d0        ; the size of available ram
  85.     addi.l    #$80,d0        ; ...but big enough for at
  86.                 ; least 8 jobs.
  87.     bsr.s    LIMIT_TBLS    ; Limit table size to 120
  88.                 ; jobs and 360 channels.
  89. ; tables must finish on a 512 byte boundary
  90.     add.l    a2,d0        ; Make sure tables finish
  91.     addi.l    #$1FF,d0     ; on a 512 byte boundary
  92.     andi.w    #-$200,d0    ; by tweaking the combined
  93.     sub.l    a2,d0        ; length of channel and job
  94.     move.l    d0,d1        ; tables. Length in d0 & d1
  95.     bsr.s    LIMIT_TBLS    ; no more than 120 jobs.
  96.     lsr.l    #2,d0        ; New length of job table
  97.     sub.l    d0,d1        ; New length of channel tbl
  98.     move.l    a2,a0        ; Save start of job table.
  99. ;
  100.     moveq    #-$1,d6
  101.     clr.w    d6
  102.     lsl.l    #$8,d6        ; d6 = FF00 0000
  103. ; initialise job table.
  104.     bsr.s    INI_TABLE
  105. ; initialise channel table.
  106.     move.l    d1,d0
  107.     bsr.s    INI_TABLE
  108. ;
  109.     bra.s    LOW_USE
  110. ; subroutine to limit the combined lengths of job and channel
  111. ; tables to to that required for 120 jobs and 360 channels.
  112. LIMIT_TBLS:
  113.     moveq    #$78,d6
  114.     lsl.l    #4,d6        ; move.l   #$780,d6
  115.     cmp.l    d6,d0
  116.     bls.s    X_LIMIT
  117.     move.l    d6,d0
  118. X_LIMIT:
  119.     rts
  120. ; subroutine to return the maximum length of the slave block
  121. ; table given d0 as himem.
  122. SLVTBL_LEN:
  123.     addi.l    #$1FF,d0
  124. ; subroutine to find how far into the slave tables, the entry
  125. ; for memory address d0 is.
  126. SLVTBL_POS:
  127.     sub.l    a6,d0        ; Slave blocks start at the
  128.     andi.w    #-$200,d0    ; sys vars and are each 512
  129.     lsr.l    #6,d0        ; bytes long. Each table
  130.     rts            ; entry is 8 bytes long.
  131. ; subroutine to set slave, job or channel pointers.
  132. INI_TABLE:
  133.     move.l    a2,(a3)+     ; Current entry.
  134.     move.l    a2,(a3)+     ; Start of table.
  135.     lea    0(a2,d0.l),a0
  136. INI_TBL1:
  137.     move.l    d6,(a2)+
  138.     cmpa.l    a0,a2
  139.     blt.s    INI_TBL1
  140.     move.l    a2,(a3)+     ; End of table.
  141.     addq.l    #4,a3
  142.     rts
  143. ; continue by finding the lowest usable address.
  144. LOW_USE:
  145.     cmpa.l    a4,a2        ; which is greater, lomem
  146.     bgt.s    SET_LOW        ; or top of channel table?
  147.     move.l    a4,a2
  148. SET_LOW:
  149.     move.l    a2,SV_CHEAP(a6)    ; Set base of common heap.
  150.     move.l    a2,SV_FREE(a6)    ; Set base of free area.
  151.  
  152. ; find usable entries in the slave block table.
  153.     move.l    a2,d0        ; Find how many are used up
  154.     bsr.s    SLVTBL_LEN    ; by the tables themselves
  155.     move.l    d0,a2        ; Address of first free
  156.     adda.l    a7,a2        ; entry in ->a2.
  157.  
  158.     move.l    a5,a3        ; clear 512 bytes between
  159.     moveq    #$7F,d0        ; RAMTOP and base of BASIC
  160.                 ; stack
  161. CLRBASLUP:
  162.     clr.l    -(a3)
  163.     dbra    d0,CLRBASLUP
  164.  
  165.     move.l    a3,SV_BASIC(a6)    ; address of BASIC stack.
  166.  
  167.     move.l    a3,d0        ; Find address of first
  168.     bsr.s    SLVTBL_POS    ; entry made unusable by
  169.     move.l    d0,a3        ; BASIC stack in ->a3.
  170.     adda.l    a7,a3
  171.     move.l    a2,d0        ; Set SV.BTPNT half way
  172.     add.l    a3,d0        ; between the first unused
  173.     lsr.l    #4,d0        ; entry and the last, but
  174.     lsl.l    #3,d0        ; must be divisible by 8.
  175.     move.l    d0,SV_BTPNT(a6)    ; Store most recent block.
  176. ; initialise slave table entries.
  177.     moveq    #$1,d0
  178.     ror.l    #$8,d0        ; d0 = %0100 0000
  179. SLV_INIT:
  180.     move.l    d0,(a2)+     ; Put 0100 0000 0000 0000
  181.     clr.l    (a2)+        ; into entries for usable
  182.     cmpa.l    a3,a2        ; blocks.
  183.     blt.s    SLV_INIT
  184. RLOC0F    move.l    #BAS_STARt-ORG0,a1
  185. RLOC10    move.l    #SHLST-ORG0,A5
  186.     MOVE.L    A5,SV_SHLST(A6)    ; pointer to list of
  187.                 ; scheduler tasks
  188. RLOC11    move.l    #DRLST-ORG0,A5
  189.     MOVE.L    A5,SV_DRLST(A6)    ; pointer to list of device
  190.                 ; drivers
  191.     ADDQ.B    #1,SV_NETNR(A6)    ; network station number
  192.     ADDQ.B    #8,SV_MCSTA(A6)    ; current value of MC status
  193.                 ; register
  194.     MOVE.W    #$1E,SV_ARDEL(A6) ; auto repeat delay
  195.     ADDQ.W    #2,SV_ARFRQ(A6)    ; autorepeat 1/freq.
  196.     ADDQ.W    #3,SV_CQCH(A6)    ; ctrl. C
  197. RLOC12    MOVE.L    #(MSG_LIST-ORG0),SV_MGTAB(A6) ; sys messages
  198. RLOC13    MOVE.L    #(KEY_TRA-ORG0),SV_TRTAB(A6) ; key trnslation
  199. ; Initialise BASIC
  200.     MOVEA.L    SV_JBBAS(A6),A4    ; pointer to base of Job
  201.                 ; table
  202.     MOVE.L    A4,SV_JBPNT(A6)    ; pointer to current Job
  203.                 ; table entry
  204.     MOVEA.L    SV_TRNSP(A6),A3    ; base of transient program
  205.                 ; area
  206.     CLR.L    -(A3)
  207.     MOVEA.L    SV_BASIC(A6),A0    ; base of basic stack
  208.     MOVE.L    A0,(A4)        ; address of job 0: BASIC
  209.     MOVE.B    #$20,JB_PRINC(A0) ; BASIC's priority increment
  210.     MOVE.L    A3,USP
  211.     LEA    JB_END(A0),A6
  212.     MOVEA.L    A3,A5
  213.     SUBA.L    A6,A5        ; A5 = Basic area
  214.     move.w    #0,SR        ; user mode on
  215.     jmp    (a1)        ; start BASIC interpreter
  216.  
  217. ;*/endoverlay
  218. ; --------------------------------------------------------------
  219. ;*/endfile
  220.